import { View, Text, Button, Input, Textarea } from "@tarojs/components"
import Taro, { getCurrentPages, getStorageSync, useDidShow } from '@tarojs/taro'
import Comments from "../../components/comments/comments"
import { AtAccordion, AtButton, AtForm, AtList, AtTextarea } from "taro-ui"
// import enrollComments from "../../components/enroll_comments/enroll_comments"
import { useEffect, useRef, useState } from "react"
import "./test.scss"
import { values } from "lodash"
import Publication_onself from "../../components/publication_oneself/publication_oneself"
const Dynamic = () => {

    //用于标题栏是否打开,默认关闭
    const [isopen1, setOpen1] = useState(true)
    const [isopen2, setOpen2] = useState(false)
    const [isopen3, setOpen3] = useState(false)
    // 各个数据储存
    const [morning, setMorning] = useState(undefined)
    const [aft, setAft] = useState(undefined)
    const [night, setNight] = useState(undefined)
    //用来零时保存数据
    // const [data, setData] = useState(undefined)
    // const [data1, setData1] = useState(undefined)
    // const [data2, setData2] = useState(undefined)
    // const [data3, setData3] = useState(undefined)
    // const [list, setList] = useState([])
    //用来保存用户输入的数据
    const list = useRef({})
    const [lists, setLists] = useState([])
    //更新零时保存数据
    // const clearDt = () => {
    //     setData(undefined)
    //     setData1(undefined)
    //     setData2(undefined)
    //     setData3(undefined)
    // }
    // const monData = useRef();


    //当每个导航栏关闭时就会保存当前的数据
    let newList = [{}]
    const Updta = (num) => {
        // let count=0
        // 最后的提交按钮的操作，把之前三个时间段的数据进行更新
        // useEffect(() => {
        switch (num) {
            case 0:
                setOpen1(!isopen1)//改变状态
                // let newList = [data, data1, data2]
                // let newList=data
                // console.log("newlist:", newList)
                // setMorning(newList)
                break
            case 1:
                // clearDt()
                setOpen2(!isopen2)//改变状态
                // let newList1 = [data, data1, data2, data3]
                // let newList1=data1
                // setAft(newList1)
                // clearDt()
                // setAft(data)
                // data.splice(0)
                break
            case 2:
                // clearDt()
                setOpen3(!isopen3)//改变状态
            // // let newList2 = [data, data1, data2]
            // let newList2=data2
            // setNight(newList2)
            // // clearDt()
            // break
        }
        // }, []);
        newList = [{
            morning: morning,
            aft: aft,
            night: night
        }]
        //写入数组
        // list.current = newList
        
            setLists(newList)
        
    }
    // console.log("list:", list.current[0])
    console.log("newlists:", lists)

    // useDidShow(() => {
    //     setLists(newList)
    // })
    //调用云函数
    const handleUpdata = () => {
        console.log("你点击的submit")

        Taro.cloud.callFunction({
            name: "publication",
            data: {
                $url:"Update",
                data: lists[0],
                reception_person: "小男孩",
            }
        }).then(() => {
            Taro.showModal({
                title: '温馨提示',
                content: '您已成功提交',
                showCancel: false
            });
            return;
        })
    }
    return (
        <View style="background-color: antiquewhite;">
            <Publication_onself/>
        </View>
    )
}
export default Dynamic
